/*
	PlAr is Platform Arena: a 2D multiplayer shooting game
	Copyright (c) 2010, Antonio Ragagnin <spocchio@gmail.com>
    All rights reserved.

    This file is licensed under the New BSD License.
*/

package plar.core;

import java.io.Serializable;
import java.util.Comparator;

import org.jbox2d.common.Vec2;
/**
 * Sprite contains the graphical informations to represent an {@link Element}.
 * All properties are pure fields  (not classes) to make easy the UDP transfer in the client server process.
 *
 * @author Antonio Ragagnin
 *
 */
public class Sprite implements Serializable {
    private static final long serialVersionUID=1L;
	
    String filename;
	
	/**
	* se if it is visible
	*/
    public boolean visible=true;
	
    public float sizex=0;
    public float sizey=0;
    public float offsetx=0;
    public float offsety=0;
	public float angle=0;
	
	/**
	* do not stretch the image but repeat it inside the container.
	*/
    public boolean texturized = false;
	/**
	* the duration of this single sprite.
	*/
    public float time;

	/**
	* @param t duration of the sprite
	*/
    public Sprite(float t) {
        filename = new String();
        time = t;
    }
	/**
	* @param t duration of the sprite
	* @param s path of the image.
	*/
    public Sprite(String s, float t) {
        filename = s;
        time = t;
    }
	/**
	* @param t duration of the sprite
	* @param s path of the image.
	* @param p dimension of the sprite.
	*/
    public Sprite(String s, Vec2 p, float t) {
        filename = s;
        sizex = p.x;
        sizey = p.y;

        time = t;
    }

    public String getFileName() {
        return filename;
    }

    public void setFileName(String s) {
        filename = s;
    }
    public String toString()
    {
        return filename+","+offsetx+"x"+offsety+","+sizex+"x"+sizey+","+texturized+","+time;
    }

    public boolean equals(Object o)

    {   Sprite s = (Sprite)o;
        boolean fn=true;
        if(filename!=null && s.filename!=null) fn = s.filename.equals(filename);
        else if( filename!=null && s.filename==null) fn=false;
        else if( filename==null && s.filename!=null) fn=false;
        else fn=true;
        if(s!=null) {

            boolean x= 		(s.angle==angle &&
                             fn &&
                             s.visible == visible &&
                             s.sizex == sizex &&
                             s.sizey == sizey &&
                             s.offsetx == offsetx &&
                             s.offsety == offsety &&
                             s.texturized == texturized &&
                             s.time == time );
            //Common.info(7, "->"+x);
            return x;
        }
        //Common.info(7, "-> ???");
        return false;

    }



}
